<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="批次号:" prop="batch.value">
                            <el-input v-model="queryParams.batch.value" placeholder="请输入批次号" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="合并批次号:" prop="merge_batch.value">
                            <el-input v-model="queryParams.merge_batch.value" placeholder="请输入合并批次号" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="编号:" prop="brand.value">
                            <el-input v-model="queryParams.brand.value" placeholder="请输入编号" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="申请人:" prop="admin_id.value">
                            <el-input v-model="queryParams.admin_id.value" placeholder="请输入申请人" clearable />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="审核状态:" prop="apply_status.value">
                            <el-input v-model="queryParams.apply_status.value" placeholder="请输入审核状态" clearable />
                        </el-form-item>
                    </el-col> -->
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="产品id:" prop="product_id.value">
                            <el-input v-model="queryParams.product_id.value" placeholder="请输入产品id" clearable />
                        </el-form-item>
                    </el-col> -->
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="申请类型:" prop="apply_type.value">
                            <el-input v-model="queryParams.apply_type.value" placeholder="请输入申请类型" clearable />
                        </el-form-item>
                    </el-col> -->
                  
                    <el-col :md="6" :sm="12">
                        <el-form-item label="申请时间:" prop="apply_time.value">
                            <el-date-picker
                                v-model="queryParams.apply_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                          </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <!-- <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button> -->
                </el-col>
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleModification" v-hasPermi="api.merge_batch_number">合并批次号</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="" align="left">
                        <template slot-scope="scope">
                            <el-button class="btn-mar" size="mini" type="primary" @click="handleEdit(scope.row)" v-hasPermi="api.edit">详情</el-button>
                            <!-- <el-button class="btn-mar" size="mini" type="info" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button> -->
                            <el-button class="btn-mar" size="mini" type="danger" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>

                        </template>
                    </el-table-column>
                </template>
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '批次号',
                    prop: 'batch',
                },
                {
                    visible: true,
                    label: '编号',
                    prop: 'brand',
                },
                // {
                //     visible: true,
                //     label: '颜色',
                //     prop: 'color',
                // },
                // {
                //     visible: true,
                //     label: 'sku',
                //     prop: 'sku',
                // },
                {
                    visible: true,
                    label: '申请数量',
                    prop: 'num',
                },
                {
                    visible: true,
                    label: '申请人',
                    prop: 'admin_title',
                },
                {
                    visible: true,
                    label: '合并批次号',
                    prop: 'merge_batch',
                },
                {
                    visible: true,
                    label: '状态',
                    prop: 'merge_status_title',
                },
                // {
                //     visible: true,
                //     label: '申请类型',
                //     prop: 'applytype_title',
                // },
            
                {
                    visible: true,
                    label: '申请时间',
                    prop: 'apply_time',
                },

            ],
            // 接口地址
            api: {
                index: `/admin/purchase/index`,
                find: `/admin/purchase/find`,
                add: `/admin/purchase/add`,
                edit: `/admin/purchase/edit`,
                delete: `/admin/purchase/delete`,
                export: `/admin/purchase/export`,
                merge_batch_number: `/admin/purchase/merge_batch`,
                status: `/admin/purchase/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                // color: { value:undefined, op: '%like%'},
                brand: { value:undefined, op: '%like%'},
                admin_id: { value:undefined, op: '='},
                 // product_id: { value:undefined, op: '='},
                apply_type: { value:undefined, op: '='},
                batch: { value:undefined, op: '%like%'},
                merge_batch: { value:undefined, op: '%like%'},
                apply_time: { value:[], op: 'range'},

            },
            batchs:[],
        }
    },
    created () {
        this.initIndex()
    },
    watch: {
        
    },
    methods: {
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        selectionChange(selection) {
            this.batchs = selection.map(item => item['batch'])
        },
        handleModification(row) {
            if(this.batchs == ''){
                return this.msgError('请勾选再操作')
            }
            this.$confirm(`是否确认合并批次号，过程大概需要一分钟?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    return this.request.post(this.api.merge_batch_number, { batchs: this.batchs })
                })
                .then(() => {
                    this.initIndex()
                    this.msgSuccess('操作成功')
                })
                .catch(() => {})
        },
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
